package project;

import java.io.IOException;

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

import jxl.read.biff.BiffException;

import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
public class Plane extends SeatHandler{
	
	Seat[][] firstClass = new Seat[3][6];
	Seat[][] business = new Seat[3][6];
	Seat[][] coach = new Seat[3][6];
	
	int planeID;
	

	public Plane(int planeID) throws BiffException, IOException, WriteException {
		
		
		this.planeID = planeID;
		
		WritableWorkbook hangar;
		hangar = Workbook.createWorkbook(new File("hangar.xls"));
		WritableSheet planeSheet = hangar.createSheet("" + this.planeID, this.planeID);
		
		
		String section;

		char row = ('A'-1);
		int status = 0;
		int adder = 0;
		
		section = "First"; //first class section
		Label rowLetter = new Label(0, 0, "");
		Number colNumber = new Number(0, 0, 0);
		Number statNumber = new Number(0, 0, 0);
		Label sectionLabel = new Label(0, 0, "");

		for (int fRow = 0; fRow < 3; fRow++){ //generate first class
			row++;

			for (int fCol = 0; fCol < 6; fCol++) {

				firstClass[fRow][fCol] = new Seat(fCol+1, row, status, section);
				
				switch(fRow) {
				case 0: {rowLetter = new Label(0, fCol, "" + row);
						planeSheet.addCell(rowLetter);
						colNumber = new Number(1, fCol, fCol+1);
						planeSheet.addCell(colNumber);
						statNumber = new Number(2, fCol, 0);
						planeSheet.addCell(statNumber);
						sectionLabel = new Label(3, fCol, section);
						planeSheet.addCell(sectionLabel);}
				case 1: {rowLetter = new Label(0, fCol+adder, "" + row);
						planeSheet.addCell(rowLetter); 
						colNumber = new Number(1, fCol+adder, fCol+1);
						planeSheet.addCell(colNumber); 
						statNumber = new Number(2, fCol+adder, 0);
						planeSheet.addCell(statNumber);
						sectionLabel = new Label(3, fCol+adder, section);
						planeSheet.addCell(sectionLabel);}
				case 2: {rowLetter = new Label(0, fCol+adder, "" + row);
						planeSheet.addCell(rowLetter); 
						colNumber = new Number(1, fCol+adder, fCol+1);
						planeSheet.addCell(colNumber); 
						statNumber = new Number(2, fCol+adder, 0);
						planeSheet.addCell(statNumber);
						sectionLabel = new Label(3, fCol+adder, section);
						planeSheet.addCell(sectionLabel);}
				}
				

			} //end first class column
			adder+=6;
		} //end first class row
		

		section = "Business"; //business class section
		
		for (int bRow = 0; bRow < 3; bRow++){ //business class generate
			row++;

			for (int bCol = 0; bCol < 6; bCol++) {

				business[bRow][bCol] = new Seat(bCol+1, row, status, section);
				
				switch(bRow) {
				case 0: {rowLetter = new Label(0, bCol+adder, "" + row);
						planeSheet.addCell(rowLetter);
						colNumber = new Number(1, bCol+adder, bCol+1);
						planeSheet.addCell(colNumber);
						statNumber = new Number(2, bCol+adder, 0);
						planeSheet.addCell(statNumber);
						sectionLabel = new Label(3, bCol+adder, section);
						planeSheet.addCell(sectionLabel);}
				case 1: {rowLetter = new Label(0, bCol+adder, "" + row);
						planeSheet.addCell(rowLetter); 
						colNumber = new Number(1, bCol+adder, bCol+1);
						planeSheet.addCell(colNumber); 
						statNumber = new Number(2, bCol+adder, 0);
						planeSheet.addCell(statNumber);
						sectionLabel = new Label(3, bCol+adder, section);
						planeSheet.addCell(sectionLabel);}
				case 2: {rowLetter = new Label(0, bCol+adder, "" + row);
						planeSheet.addCell(rowLetter); 
						colNumber = new Number(1, bCol+adder, bCol+1);
						planeSheet.addCell(colNumber); 
						statNumber = new Number(2, bCol+adder, 0);
						planeSheet.addCell(statNumber);
						sectionLabel = new Label(3, bCol+adder, section);
						planeSheet.addCell(sectionLabel);}
				}
				

			} //end business class column
			adder+=6;
		} //end business class row

		section = "Coach";

		for (int cRow = 0; cRow < 3; cRow++){ //coach class generate
			row++;

			for (int cCol = 0; cCol < 6; cCol++) {

				coach[cRow][cCol] = new Seat(cCol+1, row, status, section);
				
				switch(cRow) {
				case 0: {rowLetter = new Label(0, cCol+adder, "" + row);
						planeSheet.addCell(rowLetter);
						colNumber = new Number(1, cCol+adder, cCol+1);
						planeSheet.addCell(colNumber);
						statNumber = new Number(2, cCol+adder, 0);
						planeSheet.addCell(statNumber);
						sectionLabel = new Label(3, cCol+adder, section);
						planeSheet.addCell(sectionLabel);}
				case 1: {rowLetter = new Label(0, cCol+adder, "" + row);
						planeSheet.addCell(rowLetter); 
						colNumber = new Number(1, cCol+adder, cCol+1);
						planeSheet.addCell(colNumber); 
						statNumber = new Number(2, cCol+adder, 0);
						planeSheet.addCell(statNumber);
						sectionLabel = new Label(3, cCol+adder, section);
						planeSheet.addCell(sectionLabel);}
				case 2: {rowLetter = new Label(0, cCol+adder, "" + row);
						planeSheet.addCell(rowLetter); 
						colNumber = new Number(1, cCol+adder, cCol+1);
						planeSheet.addCell(colNumber); 
						statNumber = new Number(2, cCol+adder, 0);
						planeSheet.addCell(statNumber);
						sectionLabel = new Label(3, cCol+adder, section);
						planeSheet.addCell(sectionLabel);}
				}

			} //end coach class row
			adder+=6;
		} //end coach class column

		hangar.write();
	    hangar.close();
		
	}
	
	
	public void updatePlaneX() {
		
		
	}
	
	public void printPlane() {
		
		System.out.println("Plane Number: " + planeID);
		System.out.println("-----------------------------------------------------");
		
		for (int fRow = 0; fRow < 3; fRow++){ //print first class
			
			System.out.println("");

			for (int fCol = 0; fCol < 6; fCol++) {

				System.out.print(" | " + firstClass[fRow][fCol]);

			} //end first class row
		} //end first class column
		
		System.out.println("");
		System.out.println("-----------------------------------------------------");
		
		for (int bRow = 0; bRow < 3; bRow++){ //business class print
			
			System.out.println("");

			for (int bCol = 0; bCol < 6; bCol++) {

				System.out.print(" | " + business[bRow][bCol]);

			} //end business class row
		} //end business class column
		
		
		System.out.println("");
		System.out.println("-----------------------------------------------------");
	
		for (int cRow = 0; cRow < 3; cRow++){ //coach class print
			
			System.out.println("");

			for (int cCol = 0; cCol < 6; cCol++) {

				System.out.print(" | " + coach[cRow][cCol]);

			} //end coach class row
		} //end coach class column
		
		System.out.println("\n");
	}
	
	public void setSeat(String inputSection, char inputRow, int inputCol, int inputStatus) {
		
		if (inputSection.equals("First")) {
			firstClass[decodeRow(inputRow)][decodeCol(inputCol)].setStatus(inputStatus);
		}
		else if (inputSection.equals("Business")) {
			business[decodeRow(inputRow)][decodeCol(inputCol)].setStatus(inputStatus);
		}
		else if (inputSection.equals("Coach")) {
			coach[decodeRow(inputRow)][decodeCol(inputCol)].setStatus(inputStatus);
		}
		
	}
	
	public void xPlane() throws BiffException, IOException {
		
		System.out.println("Plane Number: " + planeID);
		System.out.println("-----------------------------------------------------");
		
		for (int fRow = 0; fRow < 3; fRow++){ //print first class
			
			System.out.println("");

			for (int fCol = 0; fCol < 6; fCol++) {

				System.out.print(" | " + firstClass[fRow][fCol]);

			} //end first class row
		} //end first class column
		
		System.out.println("");
		System.out.println("-----------------------------------------------------");
		
		for (int bRow = 0; bRow < 3; bRow++){ //business class print
			
			System.out.println("");

			for (int bCol = 0; bCol < 6; bCol++) {

				System.out.print(" | " + business[bRow][bCol]);

			} //end business class row
		} //end business class column
		
		
		System.out.println("");
		System.out.println("-----------------------------------------------------");
	
		for (int cRow = 0; cRow < 3; cRow++){ //coach class print
			
			System.out.println("");

			for (int cCol = 0; cCol < 6; cCol++) {

				System.out.print(" | " + coach[cRow][cCol]);

			} //end coach class row
		} //end coach class column
		
		System.out.println("\n");
	}
}
